﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace V3MainTool.Model
{
    /// <summary>
    /// 翻译文件处理
    /// </summary>
    public class LocalHelper
    {
        /// <summary>
        /// 科技
        /// </summary>
        public static Dictionary<string, string> InventionsDic { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 省份
        /// </summary>
        public static Dictionary<string, string> State { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 生产方式
        /// </summary>
        public static Dictionary<string, string> ProductionMethod { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 商品
        /// </summary>
        public static Dictionary<string, string> Goods { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 建筑
        /// </summary>
        public static Dictionary<string, string> Buildings { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 特殊字段
        /// </summary>
        public static Dictionary<string, string> Interfaces { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 商品类别
        /// </summary>
        public static Dictionary<string, string> GoodsCate { get; set; } = new Dictionary<string, string>();
        public static void InitGoodsCate()
        {
            GoodsCate.Add("military", "军事");
            GoodsCate.Add("staple", "日用");
            GoodsCate.Add("industrial", "工业");
            GoodsCate.Add("luxury", "奢侈品");
        }

        public static Dictionary<string, string> GetDic(string path)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            string[] arr = File.ReadAllLines(path);
            foreach (var item in arr)
            {
                try
                {
                    string str = item.Trim();
                    if (str.Length < 2)
                    {
                        continue;
                    }
                    int index = str.IndexOf(':');
                    if (index == (str.Length - 1))
                    {
                        continue;
                    }
                    string desc = str.Substring(index).Trim();
                    if (desc[1] == '0')
                    {
                        desc = desc.Substring(2, desc.Length - 2).Trim();
                    }
                    else
                    {
                        desc = desc.Substring(1, desc.Length - 1).Trim();
                    }
                    desc = desc.Substring(1, desc.Length - 2);
                    string name = str.Substring(0, index);
                    dic.Add(name, desc);
                }
                catch (Exception err)
                {
                    Console.WriteLine(item);
                    Console.WriteLine(err.Message);
                }
            }
            return dic;
        }
        public static Dictionary<string, string> GetDic(List<string> paths)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            foreach (string path in paths)
            {
                string[] arr = File.ReadAllLines(path);
                foreach (var item in arr)
                {
                    try
                    {
                        string str = item.Trim();
                        if (str.Length < 2)
                        {
                            continue;
                        }
                        int index = str.IndexOf(':');
                        if (index == (str.Length - 1))
                        {
                            continue;
                        }
                        string desc = str.Substring(index).Trim();
                        if (desc[1] == '0')
                        {
                            desc = desc.Substring(2, desc.Length - 2).Trim();
                        }
                        else
                        {
                            desc = desc.Substring(1, desc.Length - 1).Trim();
                        }
                        desc = desc.Substring(1, desc.Length - 2);
                        string name = str.Substring(0, index);
                        dic.Add(name, desc);
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(item);
                        Console.WriteLine(err.Message);
                    }
                }
            }
            return dic;
        }
    }
}
